package com.atguigu.gmall.seckill.service.impl;

import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.seckill.mapper.SeckillGoodsMapper;
import com.atguigu.gmall.seckill.service.SeckillCacheService;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @author lfy
* @description 针对表【seckill_goods】的数据库操作Service实现
* @createDate 2022-03-26 09:41:31
*/
@Service
public class SeckillGoodsServiceImpl extends ServiceImpl<SeckillGoodsMapper, SeckillGoods>
    implements SeckillGoodsService{


    @Autowired
    SeckillGoodsMapper seckillGoodsMapper;

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    SeckillCacheService seckillCacheService;



    @Override
    public List<SeckillGoods> getTodaySeckillGoods() {

        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());

        //获取当天秒杀商品
        List<SeckillGoods> seckillGoods =  seckillCacheService.getTodaySeckillGoodsFromCache(format);
        //2022-3-26   start_time(2021-03-25 19:46:34)   end_time(2021-03-26 19:46:34)
        //商品到没到秒杀时间？
        //1、start_time < 2022-3-26 00:00:00 and end_time > 2022-3-26 23:59:59
        //2、start_time(2021-03-25) <= 2022-3-26 and end_time(2021-03-26) >= 2022-3-26



        return seckillGoods;
    }
}




